export const format_address = (
  area_string_id: string,
  city_list: city_item[],
) => {
  // 定义一个空字符串,方便闭包函数获取他
  let area_string_name: string = "";
  // 闭包递归遍历数组,如果id相等则将地址拼接到这个字符串里
  const address_arr_pusher = (
    area_string_id: string,
    city_list: city_item[],
  ) => {
    const area_id_arr = area_string_id.split(",");
    // 两个foreach来找id一样的项
    city_list.forEach((city) => {
      area_id_arr.forEach((area_id) => {
        if (city.id == area_id) {
          area_string_name = area_string_name.concat(city.cityname);
          if (city.children) {
            address_arr_pusher(area_string_id, city.children);
          }
        }
      });
    });
  };
  // 由于使用了递归函数,不能立即执行
  address_arr_pusher(area_string_id, city_list);
  return area_string_name;
};

interface city_item {
  cityname: string;
  id: number | string;
  key: number;
  label: string;
  pid: number;
  type: number;
  value: number;
  children?: city_item[];
}
